var Json = {
	zhebg: function() {
		var div = $("<div>").addClass("div_obj");
		console.log(div);
		$("body").append(div);
		var div_obj = $(".div_obj");
		var height = document.body.clientHeight;
		div_obj.css({
			'position': 'fixed',
			'left': '0',
			'top': '0',
			'z-index':'1000000000',
			'background': 'rgba(0,0,0,0.7)',
			'width': '100%',
			'height': "136%"
		});
	},
	EventStop:function(flag,event){
		document.addEventListener('touchmove',function(){
			if (flag==1) {
				event.preventDefault();
			}
		});
	}
}
//格式化时间戳
 function formatLocalTime(date) {
    var year = date.getFullYear()
    var month = date.getMonth() + 1
    var day = date.getDate()
    var hour = date.getHours()
    var minute = date.getMinutes()
    var second = date.getSeconds()
    return [year, month, day].map(formatNumber).join('-') + ' ' + [hour, minute, second].map(formatNumber).join(':')
}

function formatNumber(n) {
    n = n.toString()
    return n[1] ? n : '0' + n
}

	//显示不同的时间
	var minute = 1000 * 60; 
	var hour = minute * 60; 
	var day = hour * 24; 
	var halfamonth = day * 15; 
	var month = day * 30; 
	function getDateDiff(dateTimeStamp){ 
	var now = new Date().getTime(); 
	var diffValue = now - dateTimeStamp; 
	if(diffValue < 0){ 
	 //若日期不符则弹出窗口告之 
	// alert("你的时间超越了！"); 
	 } 
	var monthC =diffValue/month; 
	var weekC =diffValue/(7*day); 
	var dayC =diffValue/day; 
	var hourC =diffValue/hour; 
	var minC =diffValue/minute; 
	if(monthC>=1){ 
	 result=parseInt(monthC) + "个月前"; 
	 } 
	 else if(weekC>=1){ 
	 result=parseInt(weekC) + "周前"; 
	 } 
	 else if(dayC>=1){ 
	 result=parseInt(dayC) +"天前"; 
	 } 
	 else if(hourC>=1){ 
	 result=parseInt(hourC) +"个小时前"; 
	 } 
	 else if(minC>=1){ 
	 result=parseInt(minC) +"分钟前"; 
	 }else 
	 result="刚刚"; 
	return result; 
	} 

//调起H5微信支付，进行余额充值
function fmwxpay(amount,openId,token){
	var amount = amount;
	var openId = openId;
	var token = token;
	console.log(token);
	var id = sessionStorage.getItem('id');
	$.ajax({
		url: apiZ,
		type: 'POST',
		dataType: 'json',
		data: {
			data:JSON.stringify({body: "疯蜜打赏",totalFee:parseInt(amount*100),openId:openId,orderType:1,attach:1,clientType:3})
		},
		error:function(msg){
			alert('ajax请求失败'+msg.status);
		},
		success: function(text) {
			console.log(text);
			if(text.errorMsg=='-10'){
				alert(text.errorMsg);
			}else{
			appid = text.data.unifiedOrder.appid;
			nonce_str = text.data.unifiedOrder.nonceStr;
			pay_sign = text.data.unifiedOrder.paySign;
			prepay_id = text.data.unifiedOrder.prepayId;
			time_stamp = text.data.unifiedOrder.timeStamp.toString();
			console.log(typeof appid,typeof nonce_str,typeof pay_sign,typeof prepay_id,typeof time_stamp)
			console.log('appid='+appid,'nonce_str='+nonce_str,'pay_sign='+pay_sign,'prepay_id='+prepay_id,'time_stamp='+time_stamp)	
				
				if(text.errorMsg == "统一下单成功"){
		          	$getBrandWCPayRequest = {
		             	appId: appid,
		             	timeStamp: time_stamp,
			            nonceStr:nonce_str,
			            package: 'prepay_id=' + prepay_id,
			            paySign: pay_sign    
		           };
		           WeixinApi.pay($getBrandWCPayRequest,function(){
							setTimeout(billReward(amount),2000);
				    });
//					wx.chooseWXPay({
//					    timestamp: time_stamp, // 支付签名时间戳，注意微信jssdk中的所有使用timestamp字段均为小写。但最新版的支付后台生成签名使用的timeStamp字段名需大写其中的S字符
//					    nonceStr: nonce_str, // 支付签名随机串，不长于 32 位
//					    package: 'prepay_id=' + prepay_id, // 统一支付接口返回的prepay_id参数值，提交格式如：prepay_id=***）
//					    signType: 'MD5', // 签名方式，默认为'SHA1'，使用新版支付需传入'MD5'
//					    paySign: pay_sign, // 支付签名
//					    success: function (res) {
//					        // 支付成功后的回调函数
//					        alert(1)
//					    }
//					});
		        }else{
		          alert(text.errorMsg);
		        }
		  	}					
		},
		headers:{
			data:JSON.stringify({"apiCode":"1145","appVersion":"3.0.0",tokenId:decodeURIComponent(token)})
		}
	})
}

//调转到应用宝下载疯蜜APP
$('.right').click(function() {					
	window.location.href = 'http://a.app.qq.com/o/simple.jsp?pkgname=com.thindo.fmb#opened';
});
//input输入框只能输入数字和 小数点后两位
function num(obj,val){
obj.value = obj.value.replace(/[^\d.]/g,""); //清除"数字"和"."以外的字符
obj.value = obj.value.replace(/^\./g,""); //验证第一个字符是数字
obj.value = obj.value.replace(/\.{2,}/g,""); //只保留第一个, 清除多余的
obj.value = obj.value.replace(".","$#$").replace(/\./g,"").replace("$#$",".");
obj.value = obj.value.replace(/^(\-)*(\d+)\.(\d\d).*$/,'$1$2.$3'); //只能输入两个小数
}
//获取品牌消费代言操作相关系统参数
function GetrewarMax(){
	$.ajax ({
		type: "POST",
		url:apiZ,
		dataType: 'json',
		error: function(res) {
			alert ("网络错误"+res.status);
		},
		success: function(data) {
			console.log(data);
			var rewardMaxNum = data.data.playTourMax;
			var issueMini = data.data.issueMini;
			var brandRate = data.data.brandRate;
			console.log(rewardMaxNum)
			//动态设置placeholder
			$("#zd_money").attr('placeholder','最多不超过'+rewardMaxNum+'元');
			$("#re_price").attr('placeholder','不得小于'+issueMini+'元');
			$("#endorsement_fee").text("价格的"+brandRate+"%");
			sessionStorage.setItem('rewardMaxNum',rewardMaxNum);
		},
		headers: {
			data:JSON.stringify({"apiCode":"1157","appVersion":"3.1.0"})
		}
	});
};
//input输入框禁止粘贴
$("#zd_money").bind("paste",function(e){
	e.preventDefault()
})
//格式化金额
function formatCurrency(num) {
    num = num.toString().replace(/\$|\,/g,'');
    if(isNaN(num))
    num = "0";
    sign = (num == (num = Math.abs(num)));
    num = Math.floor(num*100+0.50000000001);
    cents = num%100;
    num = Math.floor(num/100).toString();
    if(cents<10)
    cents = "0" + cents;
    for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
    num = num.substring(0,num.length-(4*i+3))+','+
    num.substring(num.length-(4*i+3));
    return (((sign)?'':'-') + num + '.' + cents);
}
//设置lubo盒子的height等于屏幕的width，和客户端一样
$(".huadong").css({'height':$(window).width()+'px'});
//设置三角形盒子的height十使其位于底部
$(".huadongBg").css({'background-position-y':($(window).width())-15+'px'});
//跳转到打赏的用户头像
//$(".whoRewardNum").on("touchend",function(){
//	window.location.href = 'rewardList.html'
//});